// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
  env: 'woyaochihuoguo-997xh',
  traceUser: true,
})

const db = cloud.database()
const _ = db.command

// 云函数入口函数
exports.main = async (event, context) => {
  console.log(event)
  const wxContext = cloud.getWXContext()
  await db.collection('user').doc(event.id).update({
    data:{
      class:event.class,
      grade:event.grade,
      num:event.num,
      sex:event.sex,
      username:event.username,
      avatar:event.avatar,
      qq:event.qq
    },
  })
  return {
    event,
    openid: wxContext.OPENID,
    appid: wxContext.APPID,
    unionid: wxContext.UNIONID,
  }
}